<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/24
 * Time: 13:58
 */

namespace app\common\model\mall;


use app\common\model\common\Categories;
use app\common\model\TimeModel;

class ItemCart extends TimeModel
{
    protected $deleteTime = 'delete_time';

    /**
     * 购物车商品列表
     */
    public function item()
    {
        return $this->belongsTo('app\common\model\mall\Item','item_id','id')
            ->field('id,title,thumb,goods_price,inventory,is_discount');
    }

    /**
     * 购物车商品规格列表
     */
    public function sku()
    {
        return $this->belongsTo('app\common\model\mall\ItemSku','sku_id','id')->field('id,goods_price,sku_image,spec_sku_name,inventory');
    }


    /**
     * 购物车所属商家
     * @return \think\model\relation\BelongsTo
     */
    public function store()
    {
        return $this->belongsTo('app\common\model\mall\Store','store_id','id')->field('id,name');
    }

    public static function onAfterInsert($data){

        $article = self::withoutGlobalScope()->find($data->id);

        $article->withoutGlobalScope()->where('id',$data->id)->save(['app_id'=>self::get_appId()]);

    }
}